package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageServie;
import com.tanhua.model.db.UserInfo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.model.vo.UserInfoVoAge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage/users")
public class ManageController {

    @Autowired
    private ManageServie manageServie;

    /**
     *  用户数据翻页
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    public ResponseEntity getUsers(Long page,Long pagesize){
        PageResult result = manageServie.getUsers(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     *  用户基本资料
     * @param userID
     * @return
     */
    @GetMapping("/{userID}")
    public ResponseEntity getUser(@PathVariable Long userID){
        UserInfoVo vo = manageServie.getUser(userID);
        return ResponseEntity.ok(vo);
    }

    /**
     * 用户冻结操作
     * @param paramMap
     * @return
     */
    @PostMapping("/freeze")
    public ResponseEntity freezeUser(@RequestBody Map<String,Object> paramMap){
        Map<String,String> msg = manageServie.freezeUser(paramMap);
        return ResponseEntity.ok(msg);
    }

    /**
     *    解除冻结
     * @param paramMap
     * @return
     */
    @PostMapping("/unfreeze")
    public ResponseEntity unFreeze(@RequestBody Map<String,Object> paramMap){
        Map<String, String> msg = manageServie.unFreeze(paramMap);
        return ResponseEntity.ok(msg);
    }
}
